package com.i8office.android.zhihuixinwu.module.presenter;

import com.cyan.tools.callback.SimpleCallback;
import com.i8office.android.zhihuixinwu.bean.Code;
import com.i8office.android.zhihuixinwu.module.contract.CalendarContract;
import com.i8office.android.zhihuixinwu.module.model.CalendarModel;
import com.i8office.android.zhihuixinwu.ui.schedule.DayItem;
import com.i8office.android.zhihuixinwu.ui.schedule.EventItem;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SelfCalendarSettingPresenter extends BasePresenterImpl<CalendarContract.SelfCalendarSettingView> implements CalendarContract.SelfCalendarSettingPresenter {
    private CalendarContract.Model model;

    public SelfCalendarSettingPresenter(CalendarContract.SelfCalendarSettingView view) {
        super(view);
        model = new CalendarModel();

    }

    @Override
    public void getCalendarData(int year, int month) {
        Map<String, String> params = new HashMap<>();
        params.put("year", String.valueOf(year));
        params.put("month", String.valueOf(month));
        addDisposable(model.getCalendarData(new SimpleCallback<List<DayItem>>(mView) {
            @Override
            public void requestError(String msg) {
                super.requestError(msg);
                mView.toast(msg);
            }
            @Override
            public void requestSuccess(List<DayItem> data) {
                mView.showCalendarData(data);
            }
        }, params));
    }

    @Override
    public void getEventsByDate(int year, int month, int day) {
        Map<String, String> params = new HashMap<>();
        params.put("year", String.valueOf(year));
        params.put("month", String.valueOf(month));
        params.put("day", String.valueOf(day));
        addDisposable(model.getEventsByDate(new SimpleCallback<List<EventItem>>(mView) {
            @Override
            public void requestError(String msg) {
                super.requestError(msg);
                mView.toast(msg);
            }
            @Override
            public void requestSuccess(List<EventItem> data) {
                mView.showEventData(data);
            }
        }, params));

    }

    @Override
    public void removeEvent(String taskID) {
        Map<String, String> params = new HashMap<>();
        params.put("idList", taskID);
        addDisposable(model.removeEvent(new SimpleCallback<Code>(mView) {
            @Override
            public void requestError(String msg) {
                super.requestError(msg);
                mView.toast(msg);
            }
            @Override
            public void requestSuccess(Code data) {
                mView.deleteSuccess();
            }
        }, params));
    }
}
